using System;

namespace ClassicBehaviorTree
{
    public class TaskParallelizer : Container
    {
        public override NodeState Update()
        {
            switch (_subNodes[0].Update())//one node update, others follow
            {
                case NodeState.Ready://todo: when the timer tiktok, do the other function
                    _state = NodeState.Ready;
                    break;
                case NodeState.Success:
                    _state = NodeState.Success;
                    for (int i = 1; i < _subNodes.Count - 1; i++)
                    {
                        _subNodes[i].Update();
                        switch (_subNodes[i].Update())
                        {
                            case NodeState.Ready:
                            case NodeState.Success:
                            case NodeState.Failure:
                                break;
                            case NodeState.Abort:
                                _state = NodeState.Abort;
                                return _state;
                            default:
                                break;
                        }
                    }
                    break;
                case NodeState.Failure:
                    _state = NodeState.Failure;
                    break;
                case NodeState.Abort:
                    _state = NodeState.Abort;
                    break;
                default:
                    throw new Exception("This should never happen, but clearly it has.");
            }
            return _state;
        }
    }
}
